package com.ivo.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 
 * @author Xiaoming Wang
 */
public class ApplicationContextUtil implements ApplicationContextAware { 
	private static ApplicationContext context;
	
	public void setApplicationContext(ApplicationContext contex) throws BeansException {
		context = contex; 
	}
	
	public static ApplicationContext getContext(){ 
		return context; 
	}
	
	public static Object getBean(String beanName){
		Object bean = null;
		try {
			bean = context.getBean(beanName);
		} catch(Exception e) {
			e.printStackTrace();
		}
		return bean;
	}
	
}
